home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
By Popular Request 2.0
/
By Popular Request 2.0 (Arsenal Computer).ISO
/
amiga_2
/
base36v1.lha
/
BASE36.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-27
|
2KB
|
89 lines
#include <stdlib.h>
#include <stdio.h>
void reverse(char *);
void main(int argc, char *argv[])
{
int torip[4], todec=0, sl=0;
register int start, i, temp=1, j;
char inline[10];
for(i=0; i<4; i++)
torip[i] = 0;
if(argc > 1) {
strcpy(inline, argv[1]);
for(i=0; i<strlen(inline); i++) {
if(isalpha(inline[i])) {
reverse(inline);
sl=strlen(inline);
for(j=0; j<sl; j++) {
if(isalpha(inline[j])) {
if(islower(inline[j]))
inline[j]-=87;
else
inline[j]-=55;
} else
inline[j]-=48;
todec += temp*inline[j];
temp *= 36;
}
printf("Decimal: %d\n", todec);
printf(" RIP: %s\n", argv[1]);
return;
}
}
start = atoi(argv[1]);
torip[1] = start/36;
torip[0] = start-(36*torip[1]);
if (torip[1] > 36) {
start = torip[1];
torip[2] = start/36;
torip[1] = start-(36*torip[2]);
if (torip[2] > 36) {
start = torip[2];
torip[3] = start/36;
torip[2] = start-(36*torip[3]);
}
}
for(i=0; i<4; i++){
if (torip[i]>=0 && torip[i]<=9)
torip[i] += 48;
else
torip[i] += 55;
}
temp=1;
strcpy(inline, argv[1]);
reverse(inline);
sl=strlen(inline);
for(j=0; j<sl; j++) {
inline[j]-=48;
todec +=temp*inline[j];
temp *= 36;
}
printf("Decimal: %d\n", todec);
printf(" RIP: %c%c%c%c\n", torip[3], torip[2], torip[1], torip[0]);
return;
}
}
void reverse(register char *s)
{
register int c, i, j;
for(i=0, j=strlen(s)-1; i<j; i++, j--) {
c=s[i];
s[i]=s[j];
s[j]=c;
}
}